package com.shanzmoo.admin.web.sys;

import com.shanzmoo.admin.domain.dto.SysBillCountSaveDTO;
import com.shanzmoo.admin.domain.dto.SysBillCountUpdateDTO;
import com.shanzmoo.db.sys.entity.query.SysBillCountQuery;
import com.shanzmoo.db.sys.entity.vo.SysBillCountVO;
import com.shanzmoo.db.sys.service.ISysBillCountService;
import com.shanzmoo.db.sys.entity.SysBillCountEntity;
import com.shanzmoo.core.manager.store.SysBillCountManager;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;

/**
 * 系统单号计数表 控制层
 *
 * @author Gzhao 2021-03-04
 */
@Api(tags = "系统单号计数表")
@RestController
@RequestMapping("/sys/bill-count")
public class SysBillCountController {

    @Autowired
    private ISysBillCountService sysBillCountService;
    @Autowired
    private SysBillCountManager sysBillCountManager;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<SysBillCountVO>> pageList(@Valid @RequestBody SysBillCountQuery query) {
        PageRespBase<SysBillCountVO> pageList = sysBillCountManager.queryPage(query);
        return SHttpResponse.ok(pageList);
    }

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody SysBillCountSaveDTO saveDto) {
        sysBillCountService.save(saveDto.convertEntity());
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public SHttpResponse<Boolean> deleteById(@RequestParam(value = "id") Integer id) {
        SysBillCountEntity entity = new SysBillCountEntity();
        entity.setId(id);
        sysBillCountService.updateById(entity);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody SysBillCountUpdateDTO updateDto) {
        sysBillCountService.updateById(updateDto.convertEntity());
        return SHttpResponse.ok(Boolean.TRUE);
    }
 }
